import {createRouter,createWebHistory} from 'vue-router';
import type {RouteRecordRaw} from 'vue-router';

const basicRoutes:RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/demoGenerator' // 从根路径重定向到/demoGenerator
    },
    {
        path:'/demoForm',
        name: '表单示例',
        component: () => import('@/views/demoForm/index.vue'),
    },
    {
        path:'/demoGenerator',
        name: '设计表单示例',
        component: () => import('@/views/demoGenerator/index.vue'),
    },
];

const router = createRouter({
    history: createWebHistory('/'),
    routes: basicRoutes,
    scrollBehavior: (to, from) => {
        if (to.path !== from.path) {
            setTimeout(() => {
                const AppEL = document.getElementById('app');
                if(!AppEL) return;
                AppEL.scrollTop = 0;
            });
        }
        return { top: 0 };
    },
});

export default router;
